<?php /* @var $product Product */ ?>
<?php use_helper('Number') ?>
<?php if( $product->hasTag(Product::PROMO_TAG) ): ?>
        <div class="product promo">
    <?php elseif( $product->hasTag(Product::NEW_TAG) ): ?>
        <div class="product new">
    <?php else: ?>
        <div class="product">
    <?php endif; ?>
        <div class="watch" id="watch_<?php echo $product->getId() ?>">
        <?php echo link_to(image_tag($product->isInWatchlist() ? 'star.png' : 'watch.png'
                                    , array('border' => '0'
                                            , 'alt' => ucfirst(__('watch item'))
                                            , 'title' => ucfirst(__('watch item'))
                                            , 'id' => 'img_' . $product->getId()))
                            , '#'
                            , array( 'onclick' => $product->isInWatchlist() ? 'onFromWatchlist(' . $product->getId() . '); return false;' : 'onToWatchlist(' . $product->getId() . '); return false;'))?>
        </div>
        <div class="product_title">
            <?php echo link_to($product->getName(), 'product/show/?id='.$product->getId()); ?>
        </div>
        
        <div id="div_my_list">
        </div>
        
        <div class="product_image">
        <?php if( $product->hasPhoto($product->getId()) ): ?>
            <?php echo link_to(
                            image_tag(
                                Files::getDirPath('tiny') . $product->getPhotoName($product->getId())
                                , array(
                                    'border' => '0'
                                    , 'alt' => $product->getName()
                                    , 'title' => $product->getName()
                                )
                            )
                            , 'product/show/?id=' . $product->getId()
                        )
                    ?> 
            
        <?php //echo $product->getPhotoName() ?>
        <?php else: ?>
            ---
        <?php endif; ?>
        </div>
        <?php // if( get_user_id() ): ?>
        <div class="product_price">
            <?php if($product->hasTag(Product::PROMO_TAG)): ?>
                <span style="text-decoration: line-through;"><?php echo format_currency($product->getPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR')), $sf_user->getAttribute('currency', 'EUR')) ?></span>
                <?php echo format_currency($product->getPromoPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR'))
                						, $sf_user->getAttribute('currency', 'EUR'))?>
            <?php else: ?>
            	<?php echo format_currency($product->getPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR')), $sf_user->getAttribute('currency', 'EUR')) ?>
            <?php endif; ?>
        </div>
        <div>
            <span id="ci_<?php echo $product->getId() ?>" style="display: none; height: 16px;">...</span><br />
            <input type="text" id="pr_<?php echo $product->getId() ?>" value="1" class="add_total" style="float: left; margin: 8px 10px;" />
            <div class="add_to_cart">

            <?php echo link_to(__('Add to basket')
                            , '#'
                            , array( 'onclick' => 'addToCart('. $product->getId() .'); return false;'))?>
            </div>
        </div>
        <?php // else: ?>
<!--            ----->
        <?php //endif; ?>
        <div style="clear: both;">
            <br />
            <?php echo $product->getCode() ?>
        </div>
        <div>
            <?php echo $product->getSummary() ?>
        </div>
       
    </div>
<script type="text/javascript">
function onToWatchlist(id)
{
    jQuery.ajax({
        type: "post"
        , data: ({'id' : id})
        , dataType: "html"
        , url: "/st.php/lt/product/addtolist"
        , success: function(data) {
            jQuery('#watch_'+id).html(data)
          }
        , error: function() { console.debug("error"); }
    });
}
function onFromWatchlist(id)
{
    jQuery.ajax({
        type: "post"
        , data: ({'id' : id,'redir' : 1})
        , dataType: "html"
        , url: "/st.php/lt/product/removefromlist"
        , success: function(data) {
            jQuery('#watch_'+id).html(data)
          }
        , error: function() { console.debug("error"); }
    });
}
function addToCart(id)
{
    jQuery.ajax({
        type: "post"
        , data: ({'id' : id, qnt : jQuery('#pr_'+id).val() })
        , dataType: "html"
        , url: "/st.php/lt/cart/add"
        , success: function(data) {
            jQuery('#divCartStatus').html(data);
            OnCartItemAdded(id);
          }
        , error: function() { OnCartItemFailed(id); }
    });
}
</script>
